export default function() {
    const args = Array.from(arguments); const argsCount= args.length;
    const includesFunctionType = args[argsCount - 1] === 'function';
    const nameLength = argsCount - (includesFunctionType ? 1 : 0)
    const name = args.slice(0, nameLength).join().replace(/(,[a-z])/gi, function(match){
        return match.substr(1,1).toUpperCase();
    });
    const steps = [];
    console.log('Start to define function:', name);

    const end = function(dictionary) {
        console.log('end define')
        dictionary.verbs[name] = (function(_steps) {
            return function() {
                _steps.forEach(step => step());
            }
        })(steps)

        dictionary.verbNames[name] = dictionary.verbNames[name] || [window];
    }

    const ing = run => step => {
        steps.push(() => {
            run(step);
        })
    }

    // return state machine
    return {
        ing: ing,
        end: end
    }
};
